package order.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import order.model.MenuItem;
import order.model.TopType;
import order.service.MenuItemService;
import order.service.TopTypeService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/test")
// url映射的名称
public class TopicController {
	@Autowired
	private MenuItemService menuItemService;
	@Autowired
	private TopTypeService topTypeService;

	@RequestMapping(value = "/test.do", method = RequestMethod.POST)
	public String helloWorld(HttpServletRequest request,
			HttpServletResponse response, MenuItem menuItem) {
		Integer id = menuItemService.create(menuItem);
		System.out.print(id);

		// request.setAttribute("message",
		// "You Input Topci Id is: <b>"+id+"</b>");
		return "admin"; // 对应 /WEB-INF/jsp 目录下的 topic.jsp 文件
	}

	@RequestMapping(value = "/showTopType.do", method = RequestMethod.POST)
	public String test(HttpServletRequest request, HttpServletResponse response) {
		List<TopType> list = topTypeService.findAllTopTypes();
		for (int i = 0; i < list.size(); i++) {
			System.out.println(list.get(i).getName());
		}

		return "admin"; // 对应 /WEB-INF/jsp 目录下的 topic.jsp 文件

	}
}